package com.sgb.goods.view.adapter;

import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.goods.BR;
import com.sgb.goods.entity.OrderDetailsEntity;
import com.sgb.goods.utils.base.adapter.BaseCommonAdapter;

/**
 * 销售订单详情适配器
 * @author cyj
 */
public class SellOrderDetailsAdapter extends BaseCommonAdapter<OrderDetailsEntity.OrderCommoditiesEntity> {

    /** 默认显示最大大小 */
    public final int defaultMaxShowSize = 5;
    /** 超过最大格式是否显示全部 */
    private boolean isShowOneItem = true;

    public SellOrderDetailsAdapter(int layoutResId, int variableId) {
        super(layoutResId, variableId);
    }

    @Override
    protected void convert(BaseViewHolder baseHolder, ViewDataBinding dataBinding, OrderDetailsEntity.OrderCommoditiesEntity entity) {
        dataBinding.setVariable(BR.adapter, this);
    }

    /**
     * 显示一个item
     * 界面元素太多，用户可以展开或者收起支付信息列表，收起时默认展示一个item
     * @param b 默认true
     */
    public void showThreeItem(boolean b) {
        this.isShowOneItem = b;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        if(isShowOneItem) {
            return Math.min(getData().size(), defaultMaxShowSize);
        } else {
            return getData().size();
        }
    }
}
